class ApplicationController < ActionController::Base
  before_filter :set_i18n_locale_from_params
  before_filter :authorize
  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  protect_from_forgery with: :exception

  protected
    def authorize
      if User.count != 0
        unless User.find_by_id(session[:user_id])

          redirect_to login_url,notice: "Please log in"
        
        end
      else
        flash[:notice]="please create admin user"
        # redirect_to new_user_path
      end
    end

    def set_i18n_locale_from_params
      if params[:locale]
        if I18n.available_locales.include?(params[:locale].to_sym)
          I18n.locale = params[:locale]
        else
          flash.now[:notice] = "#{params[:locale]} translation not availabe"
          logger.error flash.now[:notice]
        end
      end
    end
    def default_url_options
      {locale: I18n.locale}
    end
end
